package org.argeproje.resim.proc;


import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.media.jai.PlanarImage;

import org.argeproje.resim.proc.data.*;

/*
Input: ImageDA
Parameters

Output: ImageDA
 */
/*
Definition
  Converts image color model to the desired color model. 
Inputs
  ImageDA
Parameters
  Conversion: Destination color type of possible values ColorConvertPR.GRAY.
Outputs
  ImageDA
 */
public class ColorConvertPR extends Processor {
	public final static int GRAY = 0;
	protected int _conversion = ColorConvertPR.GRAY;
	public void setParameters(int conversion){
		_conversion = conversion;
	}
	public void setParamConversion(int conversion){
		_conversion = conversion;
	}
	public int getParamConversion(){
		return _conversion;
	}
	//TODO:
	//GIF is not supported
	public Data process() {
		switch (getParamConversion()) {
		case ColorConvertPR.GRAY:
			PlanarImage i = getInputAsPlanarImage();
			BufferedImage original = i.getAsBufferedImage();
			BufferedImage temp = new BufferedImage(i.getWidth(), i.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
		    /*
		     * http://forums.sun.com/thread.jspa?messageID=10319595
		     */
	        Graphics g = temp.getGraphics();
	        g.drawImage(original, 0, 0, null);
	        g.dispose();
	        PlanarImage o = PlanarImage.wrapRenderedImage(temp);
			setOutput(new ImageDA(o));	
			break;
		default:
			break;
		}
		return getOutput();
	}
}
